package xdu.lz.stage1_basic.chapter3_threadCommunicate;

public class ProduceConsumer1 {
    private int i;
    private final Object LOCK = new Object();
    public void produce(){
        synchronized (LOCK){
            System.out.println("生产->"+(++i));
        }
    }
    public void consume(){
        synchronized (LOCK){
            System.out.println("消费->"+i);
        }
    }

    public static void main(String[] args) {
        ProduceConsumer1 pc = new ProduceConsumer1();
        new Thread(() -> {
            while (true){
                pc.produce();
            }
        }).start();
        new Thread(() -> {
            while (true){
                pc.consume();
            }
        }).start();
    }
}
